package com.eastfair.builder.controller;

import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.auth.dto.UserAccountDto;
import com.eastfair.builder.dto.BindBuilderServiceProviderRoleDTO;
import com.eastfair.builder.dto.RemoveBuilderServiceProviderRoleDTO;
import com.eastfair.builder.service.BuilderRegisterService;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.home.vo.HomeRegisterDataVO;
import com.eastfair.matching.dto.RemoveComplementServiceProviderRoleDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * 搭建商服务用户注册
 * </p>
 *
 * @author lyw
 * @date 2022-08-10
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/builderRegister")
@Api(value = "builderRegister", tags = "服务搭建商用户注册")
public class BuilderRegisterController {
    @Autowired
    private BuilderRegisterService builderRegisterService;


    /**
     * 搭建商服务商注册
     *
     * @param userAccountDto 用户新增实体
     * @return
     */
    @ApiOperation(value = "搭建商服务商注册", notes = "搭建商服务商注册")
    @SysLog("搭建商服务商注册")
    @PostMapping("/registerBuilderUser")
    public R<HomeRegisterDataVO> registerBuilderUser(@RequestBody UserAccountDto userAccountDto) {
        try {
            return R.success(builderRegisterService.registerBuilderUser(userAccountDto));
        } catch (BizException e) {
            return R.fail(e);
        }
    }

    /**
     * 搭建商服务商绑定角色.
     * @param bindBuilderServiceProviderRoleDTO
     * @return
     */
   @PostMapping("/bind/builderRole")
    public R<Boolean> bindBuilderServiceProviderRole(@RequestBody BindBuilderServiceProviderRoleDTO bindBuilderServiceProviderRoleDTO){
       try {
           return R.success(builderRegisterService.bindBuilderServiceProviderRole(bindBuilderServiceProviderRoleDTO));
       } catch (BizException e) {
           return R.fail(e);
       }
    }



    /**
     * 搭建商服务商移除角色
     * @param removeBuilderServiceProviderRoleDTOList
     * @return
     */
    @PostMapping("/remove/builderRole")
    public R<Boolean> removeBuilderServiceProviderRole(@RequestBody List<RemoveBuilderServiceProviderRoleDTO> removeBuilderServiceProviderRoleDTOList){

        try {
            return R.success(builderRegisterService.removeBuilderServiceProviderRole(removeBuilderServiceProviderRoleDTOList));
        } catch (BizException e) {
            return R.fail(e);
        }

    }
}
